from django.db import models

# Create your models here.
from django.db.models import ForeignKey, CharField


class ExcelData(models.Model):
    key = models.CharField(max_length=20)
    type = models.CharField(max_length=20)
    data = models.CharField(max_length=200)

    def __str__(self):
        return self.key


FILTER_CHOICES = (('STATIC', 'STATIC'), ('TEXT', 'TEXT'), ('COMBOBOX', 'COMBOBOX'),)


class ExcelFormat(models.Model):
    key = models.CharField(max_length=20)  # type: CharField
    display = models.CharField(max_length=200)
    filter = models.CharField(max_length=200, choices=FILTER_CHOICES)

    def __str__(self):
        return self.key


class ColumnFormat(models.Model):
    excel = models.ForeignKey(ExcelFormat, on_delete=models.CASCADE)  # type: ForeignKey
    key = models.CharField(max_length=20)

    format = models.CharField(max_length=20, choices=FILTER_CHOICES)
    values = models.CharField(max_length=200)
    width = models.PositiveIntegerField()

    def __str__(self):
        values_str = []
        values = self.values.split(',')
        for value in values:  # type: object
            values_str.append('\'' + value.strip() + '\'')

        return self.format + '(\'' + self.key + '\',' + str(self.width) + ',[' + ','.join(values_str) + '])'

    @property
    def javascript(self):
        # Excel.STATIC('ID', 60),
        return str(self)
